package main.IO;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

/**
 * @author ChengGM
 * @create 2017-01-13 15:11
 **/
public class IOTest {
	public static void moveFile() {
		Path source = Paths.get("d:/logs", "test2.txt");

		Path target = source.getParent().resolve("tte/test2.txt");

		try {
			System.out.println("文件字节：--------->" + Files.size(source));
			Files.move(source, target, StandardCopyOption.REPLACE_EXISTING);

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void createDir() {
		Path path = Paths.get("d:/logs/tte");
		try {
			// 创建文件夹
			if (Files.notExists(path)) {
				Files.createDirectories(path);
				System.out.println("create dir");
			} else {
				System.out.println("dir exists");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		createDir();
		moveFile();
	}
}
